package com.sky.controller.admin;

import com.sky.result.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class CommonController {
    @PostMapping("/admin/common/upload")
    public Result<String> upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String extend = originalFilename.substring(originalFilename.lastIndexOf("."));
        String newFilename = UUID.randomUUID().toString() + extend;
        file.transferTo(new File("D:\\Doug\\Pictures\\Camera Roll\\" + newFilename));
        String path = "D:\\Doug\\Pictures\\Camera Roll\\" + newFilename;
        return Result.success(path);
    }
}
